<%-- 
    Document   : changePass
    Created on : 04 1, 12, 7:23:12 PM
    Author     : RES
--%>

<%@page import="UserPackage.Hasher"%>
<%@page import="UserPackage.User"%>
<%@page import="UserPackage.UserManager"%>
<%@page import="UserPackage.inputChecker"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        String username = (String)session.getAttribute("username");
        String old = request.getParameter("oldPass");
        String newpass = request.getParameter("newPass");
        String retype = request.getParameter("retype");
        inputChecker check = new inputChecker();
        boolean result;
        boolean result2;
        result = new UserManager().checkOldPass(username, old);
        
        if(result == true)
                   {
        if (check.stringCompare(old) && check.stringCompare(newpass) && check.stringCompare(retype) &&  newpass.equals(retype) ) 
        {
            User newUser = new User();
            
            newUser.setUsername(username);
            newUser.setOldPass(old);
            newUser.setNewPass(newpass);
            String hash = new Hasher().passHasher(old);
            newUser.setHash(hash);
            
            result2 = new UserManager().changeOldPass(newUser);
           
            if (result2 == true)
                response.sendRedirect("userHomePage.jsp");
            else
                response.sendRedirect("editProfile.jsp");
                    
        }
        else
            response.sendRedirect("editProfile.jsp");
        
        }
        else
            response.sendRedirect("editProfile.jsp");
        %>
    </body>
</html>
